<?php
/**
 * Created by PhpStorm.
 * User: Thans
 * Date: 2018/6/27
 * Time: 下午1:52
 */

namespace app\common\behavior;

use think\Db;
use think\facade\Hook;

class LoadHook
{
    public function run($params)
    {
        $addons = cache('init_hook_addons');
        if (empty($addons)) {
            $addons = Db::name('hook_addons')->field('hook,addons')->where('status', 1)
                ->order('list_order ASC,id DESC')
                ->select();
            cache('init_hook_addons', $addons, null, 'init_hook_addons');
        }
        if (!empty($addons)) {
            foreach ($addons as $hookAddons) {
                Hook::add($hookAddons['hook'], $hookAddons['addons']);
            }
        }
    }
}